<?php

class DefaultController extends Controller {
    public $parents;
    public $menu;
    public $layouts="";
    public function actionIndex() {
        $this->menu = new Menu();
        $this->parents = $this->menu->findAll('menu_parent_id=0');
        $this->render('index');
       
    }
    public function actionLogin() {
        $model = new Manager();
        $error = "";
        $this->layout="";
        if (Yii::app()->request->getIsPostRequest()) {
            $model->attributes = Yii::app()->request->getPost('Manager');
            $user = $model->find('admin_name = :name', array(":name" => trim($model->admin_name)));
            if (is_null($user) === false) {
                if ($user->admin_status == "open") {
                    $passwd = $model->getSha1PassWord(trim($model->admin_pass));
                    if ($user->admin_pass == $passwd) {
                        Yii::app()->cookies->set('admin',$user->admin_name);
                        Yii::app()->cookies->set('groupId',$user->admin_group_id);

                        $this->redirect($this->createUrl('index'));
                    } else {
                        $error = Yii::t('app', '密码不正确!');
                    }
                } else {
                    $error = Yii::t('app', '帐户名被禁用!');
                }
            } else {
                $error = Yii::t('app', '帐户名不存在!');
            }
        }
        $this->render('login', array('model' => $model, 'error' => $error));
    }

}